import type {
  SearchBaseSelectors,
  SearchPageSelectors,
} from '../../../../module/page_enhancer/appearance/style_enhancement/platforms'
import { AppStyleCollections } from '../../../../types/constants'

export const BAIDU_RESULT_BASE_SELECTOR: string = `div:is(.result-op.c-container, .c-container.new-pmd)`
export const BAIDU_RESULT_MARK_SELECTOR: string = `.${AppStyleCollections.Search.class.SEARCH_RESULT_ITEMS}`

/**
 * 页面类型
 */
export enum BaiduPageType {
  Index = 'index',
  Web = 'web',
  News = 'news',
  Video = 'video',
  Note = 'note',
  More = 'more',
  Advanced = 'advanced',
  NotFound = 'not-found',
  Undefined = 'undefined',
  // 暂不支持
}

/**
 * 页面类型属性
 */
export interface BaiduPageTypeResult {
  type: BaiduPageType | 'default'
}

/**
 * 高级搜索页面 URL
 */
export const BAIDU_ADVANCE_PAGE_URL: string = 'https://www.baidu.com/gaoji/advanced.html'

// ====================================================== 基础配置 ======================================================
// 搜索框容器
export const BAI_DU_SEARCH_BOX_SELECTOR: string = '#wrapper #head #chat-input-main'
// 搜索结果项
export const BAI_DU_SEARCH_RESULT_CONTAINER_SELECTOR: string = ''
// 广告结果项
export const BAI_DU_SEARCH_AD_RESULT_CONTAINER_SELECTOR: string = ''

// 基础选择器
export const BAI_DU_SEARCH_BASE_SELECTORS: SearchBaseSelectors = {
  searchBox: {
    input: '',
    dropdown: {
      wrapper: ``,
      menu: ``,
      hotRank: ``,
      suggestions: `${BAI_DU_SEARCH_BOX_SELECTOR} #chat-input-panel:has(.ai-bdsug .bdsug-feedback)`,
      history: `${BAI_DU_SEARCH_BOX_SELECTOR} #chat-input-panel:has(.ai-bdsug .setup_storeSug)`,
      clearHistoryBtn: ``,
      clearHistoryText: ``,
    },
  },
  result: {
    container: BAI_DU_SEARCH_RESULT_CONTAINER_SELECTOR,
    item: ``,
  },
  adResult: {
    container: BAI_DU_SEARCH_AD_RESULT_CONTAINER_SELECTOR,
    item: `${BAI_DU_SEARCH_AD_RESULT_CONTAINER_SELECTOR}`,
    itemTitle: `${BAI_DU_SEARCH_AD_RESULT_CONTAINER_SELECTOR}`,
  },
  rightAside: {
    containerSelector: '',
    dragTargetSelector: `.${AppStyleCollections.Drag.AREA}`,
    dragTargetStyle: `bottom: -18px; left: -32px;`,
    handleIconStyle: ``,
    position: 'left',
  },
}

// 页面选择器
export const BAI_DU_SEARCH_PAGE_SELECTORS: SearchPageSelectors = {
  [BaiduPageType.Web]: {
    ...BAI_DU_SEARCH_BASE_SELECTORS,
  },
  [BaiduPageType.News]: {
    ...BAI_DU_SEARCH_BASE_SELECTORS,
    searchBox: {
      input: '',
      dropdown: {
        wrapper: ``,
        menu: ``,
        suggestions: `#wrapper #head #form .bdsug:not(:has(.setup_storeSug))`,
        history: `#wrapper #head #form .bdsug:has(.setup_storeSug)`,
        clearHistoryBtn: ``,
        clearHistoryText: ``,
      },
    },
  },
  [BaiduPageType.Note]: {
    ...BAI_DU_SEARCH_BASE_SELECTORS,
    searchBox: {
      input: '',
      dropdown: {
        wrapper: ``,
        menu: ``,
        hotRank: ``,
        suggestions: `#page-hd #head #form .note-sug-container`,
        history: ``,
        clearHistoryBtn: ``,
        clearHistoryText: ``,
      },
    },
  },
  [BaiduPageType.Index]: {
    ...BAI_DU_SEARCH_BASE_SELECTORS,
    searchBox: {
      input: '',
      dropdown: {
        wrapper: ``,
        menu: ``,
        hotRank: ``,
        suggestions: `${BAI_DU_SEARCH_BOX_SELECTOR} #chat-input-panel:not(:has(.ai-bdsug .setup_storeSug))`,
        history: `${BAI_DU_SEARCH_BOX_SELECTOR} #chat-input-panel:has(.ai-bdsug .setup_storeSug)`,
        clearHistoryBtn: ``,
        clearHistoryText: ``,
      },
    },
  },
}
